<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ServiceBuyLog extends Model
{
    use HasFactory;

    protected $table = 'sp_service_buy_log';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //service_type服务类型 1合同  2短信
    const SERVICE_BUY_LOG_SERVICE_TYPE_CONTRACT = 1;//合同
    const SERVICE_BUY_LOG_SERVICE_TYPE_MSG = 2;//短信
    const SERVICE_BUY_LOG_SERVICE_TYPE_RISK = 3;//百融风控
    const SERVICE_BUY_LOG_SERVICE_TYPE_RISK_BOOLEA = 4;//布尔数据
    const SERVICE_BUY_LOG_SERVICE_TYPE_RISK_RADAR = 6;//雷达报告
    const SERVICE_BUY_LOG_SERVICE_TYPE_RISK_EDU = 7;//学历报告
    const SERVICE_BUY_LOG_SERVICE_TYPE_RISK_CRE = 8;//征信报告

    //buy_type购买类型   1自动充值   2手动充值
    const SERVICE_BUY_LOG_BUY_TYPE_AUTOPAY = 1;//自动充值
    const SERVICE_BUY_LOG_BUY_TYPE_MANUALPAY = 2;//手动充值

    //获取购买类型
    public static function getBuyType($buy_type)
    {
        $buy_log_buy_type = array(1 => '自动充值', 2 => '手动充值'); //购买类型   1自动充值   2手动充值
        return getValue($buy_type, $buy_log_buy_type);
    }

    //查询购买记录
    protected function GetServiceBuyLog($pageSize, $where)
    {
        $select = array('sbl.*', 'oa.username');
        $data = $this
            ->from('sp_service_buy_log as sbl')
            ->leftjoin('sp_other_admin as oa', 'oa.id', 'sbl.user_id')
            ->select($select)
            ->where($where)
            ->orderBy('sbl.id', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }


}
